/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javalens.astronomy;

import javalens.util.CalculationException;
import javalens.util.Util;

/**
 *
 * @author vermaak
 */
public class LightCurve {

    private double[] days;
    private double[] mags;
    private double[] errors;
    private Event event;

    public LightCurve() {
    }

    public double[] getDays() {
        return days;
    }

    public double[] getMags() {
        return mags;
    }

    public double[] getErrors() {
        return errors;
    }

    public void setErrors(double[] errors) {
        assert (days.length == errors.length);
        this.errors = new double[errors.length];
        System.arraycopy(errors, 0, this.errors, 0, errors.length);

    }

    public void set(double[] days, double mags[]) {
        assert (days.length == mags.length);
        this.days = new double[days.length];
        this.mags = new double[mags.length];
        System.arraycopy(days, 0, this.days, 0, days.length);
        System.arraycopy(mags, 0, this.mags, 0, mags.length);
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    public static LightCurve createRegularTimeCurve(double startDay, double endDay, int nPoints, Event event) throws CalculationException {
        double[] days = Util.createRegularArray(startDay, endDay, nPoints);
        return createFromTimeArray(days, event);
    }

    public static LightCurve createFromTimeArray(double[] days, Event event) throws CalculationException {
        LightCurve ret = new LightCurve();
        double[] mags = new double[days.length];
        double[] errs = new double[days.length];
        for (int i = 0; i < days.length; ++i) {
            mags[i] = Calculations.calcMagnitude(event, days[i]);
            errs[i] = 0.01;
        }
        ret.set(days, mags);
        ret.setEvent(event);
        ret.setErrors(errs);
        return ret;
    }
}
